$(function(){
	var serch_list = utilModule.getStorage("local_find_doctor");
	if(serch_list != null){
		var arr = serch_list.split(",")
		var html = ""
		for (var i = arr.length-1; i>=0; i--) {
			html+= '<li>'+arr[i]+'<i class="remove_one iconfont mui-icon icon-020" data-name="'+arr[i]+'"></i></li>';
		}

		$(".online-serchHistory ul").empty();
		$(".online-serchHistory ul").append(html);
	}

	
	$(".submitok").on("click",function(){
    	var key = $(".key").val();
    	var serch_list = utilModule.getStorage("local_find_doctor");
    	if(serch_list == null){
    		utilModule.setStorage("local_find_doctor",key);
    	}else{
    		var aa = serch_list.search(key);
    		if(serch_list.search(key)==-1){
    			utilModule.setStorage("local_find_doctor",serch_list+","+key);
    		}
    		//window.location.href
    		
    	}
    	//location.reload();
    	utilModule.setStorage("serch_key",key);
    	window.location.href="../../html/onlineContinuation/online-doctor.html";
    })
	$(".remove_all").on("click",function(){
		utilModule.removeStorage("local_find_doctor");
		location.reload();
	});
	$(".remove_one").on("click",function(event){
		var key = $(this).data("name");
		var serch_list = utilModule.getStorage("local_find_doctor");
		var arr = serch_list.split(",");
		for (i in arr) {
			if(arr[i]==key){
				arr.splice(i, 1);
			}
		}
		var new_serch_list =arr.join(",");
		
		utilModule.removeStorage("local_find_doctor");
		if(arr.length>=1){
			utilModule.setStorage("local_find_doctor",new_serch_list);
		}
		
		location.reload();
	});
	
	$(".online-serchHistory ul li").on("click",function(event){
		var key = $(this).text();
		console.log(key)
    	utilModule.setStorage("serch_key",key);
    	window.location.href="../../html/onlineContinuation/online-doctor.html";
	});
});